ceTe Software Help Library for Java August - 2020
DynamicPDF Generator for Java / Programming with Generator for Java / XMP MetaData
In This Topic
    XMP MetaData
    In This Topic

    The XMP (Extensible Metadata Platform) provides a standard format for the creation, processing and interchange of metadata for a wide variety of applications. Metadata is data that describes the characteristics or properties of a document. It can be distinguished from the main contents of a document. For example, for a word processing document, the contents include the actual text data and formatting information, while the metadata might include such properties as author, modification date, or copyright status.

    In order to make  applications work more efficiently with metadata, there must be a common standard that they understand. XMP—the Extensible Metadata Platform—is designed to provide such a standard.

    XMP is provided with Schemas: Predefined sets of metadata property definitions that are relevant for a wide range of applications.

    • The Dublin Core Schema provides a set of commonly used properties.
    • The XMP Basic Schema contains properties that provide basic descriptive information.
    • The Rights Management Schema includes properties related to rights management. These properties specify information regarding the legal restrictions associated with a resource.
    • The Basic Job Ticket Schema describes very simple workflow or job information.
    • The Paged-Text Schema is used, to get the maximum page size and the total number of pages in a document.
    • Adobe PDF Schema specifies properties used with Adobe PDF files.

    This example shows how to create an XMP Metadata and add it to the document.

    [Java]
        import com.cete.dynamicpdf.*;
        import com.cete.dynamicpdf.xmp.*;
        import java.io.*;
        import java.util.*;
     
        public class MyClass{
            public static void main(String args[]){
               
                // Create a PDF Document
                Document document = new Document();
                document.setKeywords( "XMP, metadata, pdf, example");
                document.setTitle( "Pdf document with xmp metadata" );
               
                // Add blank pages to the document
                document.getPages().add( new Page( PageSize.LETTER ) );
                document.getPages().add( new Page( PageSize.LETTER ) );     
     
                // Create an Xmp Metadata
                XmpMetadata xmp = new XmpMetadata();
                       
                // Dublin Core Schema.
                DublinCoreSchema dc = xmp.getDublinCore();
                dc.getContributors().add( "Abc" );
                dc.getContributors().add( "Xyz" );
                dc.getContributors().add( "Pqrs" );
                dc.setCoverage( "To test all the attributes of schema's provided" );
                dc.getCreators().add( "MyProduct" );
                dc.getCreators().add( "MyCompany" );
                dc.getDate().add( new Date() );
                dc.getDescription().addLang( "en-us", "XMP Schema's test" );
                dc.setIdentifier( "First XMP pdf" );
                dc.getPublisher().add( "mydomain.com" );
                dc.getPublisher().add( "MyCompany" );
                dc.getRelation().add( "test pdf with xmp" );
                dc.getRights().setDefault( "US English" );
                dc.getRights().addLang( "en-us", "All rights reserved , MyCompany." );
                dc.setSource( "XMP Project" );
                dc.getSubject().add( "eXtensible Metadata Platform" );
                dc.getTitle().addLang( "en-us", "XMP" );
                dc.getTitle().addLang( "it-it", "XMP - Piattaforma Estendible di Metadata" );
                dc.getTitle().addLang( "du-du", "De hallo Wereld" );
                dc.getTitle().addLang( "fr-fr", "XMP - Une Platforme Extensible pour les Métédonnées" );
                dc.getTitle().addLang( "DE-DE", "ÄËßÜ Hallo Welt" );
                dc.getType().add( "Pdf file containing xmp metadata" );
                       
                // Basic Schema.
                BasicSchema bs = xmp.getBasicSchema();
                bs.getAdvisory().add( "Date" );
                bs.getAdvisory().add( "Contributors" );
                bs.setCreationDate( new Date());
                bs.setNickname( "xyz" );
                bs.getThumbnails().add(106, 80, "JPEG", getImage( "C:\thumbnail.jpg" ) );
               
                // Rights Management Schema.
                RightsManagementSchema rm = new RightsManagementSchema();
                rm.setMarked2( CopyrightStatus.PublicDomain );
                rm.getOwner().add( "MyCompany" );
                rm.getUsageTerms().addLang( "en-us", "Contact MyCompany" );
                xmp.addSchema( rm );
               
                // Basic Job Ticket Schema.
                BasicJobTicketSchema job = new BasicJobTicketSchema();
                job.getJobRef().add( "MyCompany", "Xmp Test", new URL( "http://www.mydomain.com/" ) );
                job.getJobRef().add( "MyCompany", "XMP Metadata", new URL( "http://www.mydomain.com/" ) );
                xmp.addSchema( job );
               
                // Paged-Text Schema.           
                PagedTextSchema pt = new PagedTextSchema();           
                xmp.addSchema( pt );
                /* Need not have to add Dublic core schema, Basic Schema and 
                Adobe Pdf schema at this point. These are already added internally. */
               
                // Add the Xmp Metadata to the document
                document.setXmpMetadata( xmp );             
                                             
                // Save the PDF
                document.draw("[PhysicalPath]/MyDocument.pdf");
            }
           
            private static byte[] getImage( String filePath ) {
                byte[] binaryData = null;   
                try {
                    FileInputStream inFile = new FileInputStream( filePath );
                    binaryData = new byte[ inFile.available() ];
                    inFile.read( binaryData );
                    inFile.close();
                } catch(Exception e) {
                System.out.println("EXCEPTION  "+e.getMessage());
                }           
                return binaryData;
            }       
     }
    
    See Also